package com.dbb.solrj

import org.apache.solr.client.solrj.beans.Field

class FileInfo {
	@Field
	String id
	@Field
	String name
	@Field("path")
	String absolutePath
	@Field("content_type")
	String contentType
	@Field("file_size")
	Long fileSize
	
	public FileInfo(File file) {
		this.id = file.absolutePath
		this.name = file.name
		this.absolutePath = file.absolutePath
		this.fileSize = file.size()
		this.contentType = contentType(file.absolutePath)
	}
	
	String contentType(String fileUrl) {
		try{
			URL u = new URL("file:" + fileUrl.replaceAll("\\\\", "/"))
			URLConnection uc = u.openConnection();
			String type = uc.getContentType()
			return type
		} catch (Exception e) {
			return ""
		}
		
	}
	String toString() {
		return "AbsolutePath:" + this.absolutePath + ";Name:" + this.name
	}
}
